﻿using System.Numerics;
using System.Reflection.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Diagnostics;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace MelodysDemo.EFCore.Extensions
{
    public static class ModelBuilderExtensions
    {
        public static void Seed(this ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<SurveyAnswer>(entity =>
            {
                entity.HasComment("答题记录表");

                entity.Property(e => e.Id)
                    .ValueGeneratedNever()
                    .HasComment("自增主键");

                entity.Property(e => e.ClazzId).HasComment("班级ID");

                entity.Property(e => e.ClazzQuestionnaireId)
                    .ValueGeneratedOnAdd()
                    .HasComment("教学评价ID");

                entity.Property(e => e.CostTime).HasComment("耗时(单位：秒)");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.QuestionnaireId).HasComment("问卷ID");

                entity.Property(e => e.Score).HasComment("得分");

                entity.Property(e => e.SourceDetail).HasComment("来源详情");

                entity.Property(e => e.SourceIp).HasComment("来源IP");

                entity.Property(e => e.SourceLocation).HasComment("来源IP地址");

                entity.Property(e => e.SourceType).HasComment("来源类型(1：mobile，2：pc)");

                entity.Property(e => e.Status).HasComment("状态（1：正常，0：无效）");

                entity.Property(e => e.Version).HasComment("版本号");

                entity.HasOne(d => d.ClazzQuestionnaire)
                    .WithMany(p => p.SurveyAnswers)
                    .HasForeignKey(d => d.ClazzQuestionnaireId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("survey_answer_ibfk_1");
            });

            modelBuilder.Entity<SurveyAnswerDetail>(entity =>
            {
                entity.HasComment("答题详情记录表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.AnswerId).HasComment("答题ID");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.OptionId).HasComment("选项ID");

                entity.Property(e => e.OptionSn).HasComment("选项编号");

                entity.Property(e => e.QuestionId).HasComment("问题ID");

                entity.Property(e => e.Version).HasComment("版本号");

                entity.HasOne(d => d.Answer)
                    .WithMany(p => p.SurveyAnswerDetails)
                    .HasForeignKey(d => d.AnswerId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("survey_answer_detail_ibfk_1");

                entity.HasOne(d => d.Option)
                    .WithMany(p => p.SurveyAnswerDetails)
                    .HasForeignKey(d => d.OptionId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("survey_answer_detail_ibfk_3");

                entity.HasOne(d => d.Question)
                    .WithMany(p => p.SurveyAnswerDetails)
                    .HasForeignKey(d => d.QuestionId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("survey_answer_detail_ibfk_2");
            });

            modelBuilder.Entity<SurveyBase>(entity =>
            {
                entity.HasComment("基础表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.Version).HasComment("版本号");
            });

            modelBuilder.Entity<SurveyClazz>(entity =>
            {
                entity.HasComment("班级信息表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.AdviserName).HasComment("班主任");

                entity.Property(e => e.ClazzName).HasComment("班级名称");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.Status).HasComment("班级状态(1:正常，2：结业)");

                entity.Property(e => e.StudentCount).HasComment("学生数量");

                entity.Property(e => e.TeacherName).HasComment("授课老师");

                entity.Property(e => e.Version).HasComment("版本号");
            });

            modelBuilder.Entity<SurveyClazzQuestionnaire>(entity =>
            {
                entity.HasComment("班级问卷信息表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.ClazzId).HasComment("班级ID");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.IsIpLimit).HasComment("是否开启IP限制（1：是，0：否）");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.QuestionnaireId).HasComment("问卷ID");

                entity.Property(e => e.Status).HasComment("状态（0：待发布，1：已发布，2：已停止）");

                entity.Property(e => e.Version).HasComment("版本号");

                entity.HasOne(d => d.Clazz)
                    .WithMany(p => p.SurveyClazzQuestionnaires)
                    .HasForeignKey(d => d.ClazzId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("survey_clazz_questionnaire_ibfk_1");

                entity.HasOne(d => d.Questionnaire)
                    .WithMany(p => p.SurveyClazzQuestionnaires)
                    .HasForeignKey(d => d.QuestionnaireId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("survey_clazz_questionnaire_ibfk_2");
            });

            modelBuilder.Entity<SurveyOption>(entity =>
            {
                entity.HasComment("选项信息表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.Content).HasComment("选项内容");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.QuestionId).HasComment("问题ID");

                entity.Property(e => e.QuestionnaireId).HasComment("问卷ID");

                entity.Property(e => e.Score).HasComment("分数");

                entity.Property(e => e.Sn).HasComment("选项序号");

                entity.Property(e => e.Version).HasComment("版本号");

                entity.HasOne(d => d.Question)
                    .WithMany(p => p.SurveyOptions)
                    .HasForeignKey(d => d.QuestionId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("question_key");
            });

            modelBuilder.Entity<SurveyQuestion>(entity =>
            {
                entity.HasComment("问题信息表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.QuestionnaireId).HasComment("问卷ID");

                entity.Property(e => e.Score).HasComment("分值");

                entity.Property(e => e.Sn).HasComment("序号");

                entity.Property(e => e.Title).HasComment("问题/题干");

                entity.Property(e => e.Version).HasComment("版本号");

                entity.HasOne(d => d.Questionnaire)
                    .WithMany(p => p.SurveyQuestions)
                    .HasForeignKey(d => d.QuestionnaireId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("questionnaire_id");
            });

            modelBuilder.Entity<SurveyQuestionnaire>(entity =>
            {
                entity.HasComment("问卷信息表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.QuestionCount).HasComment("问题数");

                entity.Property(e => e.Status).HasComment("状态（0：待上架，1：已启用，2：已禁用）");

                entity.Property(e => e.Title).HasComment("问卷名称");

                entity.Property(e => e.TotalScore).HasComment("总分");

                entity.Property(e => e.Version).HasComment("版本号");
            });

            modelBuilder.Entity<SurveyUser>(entity =>
            {
                entity.HasComment("用户信息表");

                entity.Property(e => e.Id).HasComment("自增主键");

                entity.Property(e => e.CreateTime).HasComment("创建时间");

                entity.Property(e => e.Creator).HasComment("创建人");

                entity.Property(e => e.IsDelete).HasComment("是否删除，0：否，1：是");

                entity.Property(e => e.ModifiedTime).HasComment("修改时间");

                entity.Property(e => e.Modifier).HasComment("修改人");

                entity.Property(e => e.Password).HasComment("密码");

                entity.Property(e => e.Phone).HasComment("手机号");

                entity.Property(e => e.Status).HasComment("状态（1：启用，0：不启用）");

                entity.Property(e => e.UserType).HasComment("用户类型（2：管理员，1：普通用户）");

                entity.Property(e => e.Username).HasComment("用户名称");

                entity.Property(e => e.Version).HasComment("版本号");
            });
        }
    }
}
